package my.senix.sc.controller;

import com.alibaba.fastjson.JSONObject;
import my.senix.sc.bean.Player;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * Created by lhs on 2018/8/30.
 */
@RestController
public class HelloController {

    //3000 QPS--短   3000-长
    @PostMapping(value = "/players",consumes={"application/json"})
    public List<Player> getPlayer(@RequestBody Player player) {
        List<Player> players=new ArrayList<>();

        for(int i=0;i<50;i++){
            Player p=new Player();
            p.setName("senix.liu["+i+"]");
            p.setAge(23+i);
            p.setAddress("Yangxin Nom"+i);
            p.setGirlFriends(Arrays.asList("dfaa","343434","dafadf","argergre","adfaf","df23ad",
                    "dfaa","343434","dafadf","argergre","adfaf","df23ad",
                    "dfaa","343434","dafadf","argergre","adfaf","df23ad",
                    "dfaa","343434","dafadf","argergre","adfaf","df23ad",
                    "dfaa","343434","dafadf","argergre","adfaf","df23ad",
                    "dfaa","343434","dafadf","argergre","adfaf","df23ad"
            ));

            players.add(p);
        }

        return players;
    }

    //2950 QPS-短   2579-长
    @PostMapping(value = "/players/str")
    public String getPlayer0(@RequestBody Player player) {
        List<Player> players=new ArrayList<>();

        for(int i=0;i<50;i++){
            Player p=new Player();
            p.setName("senix.liu["+i+"]");
            p.setAge(23+i);
            p.setAddress("Yangxin Nom"+i);
            p.setGirlFriends(Arrays.asList("dfaa","343434","dafadf","argergre","adfaf","df23ad",
                    "dfaa","343434","dafadf","argergre","adfaf","df23ad",
                    "dfaa","343434","dafadf","argergre","adfaf","df23ad",
                    "dfaa","343434","dafadf","argergre","adfaf","df23ad",
                    "dfaa","343434","dafadf","argergre","adfaf","df23ad",
                    "dfaa","343434","dafadf","argergre","adfaf","df23ad"
            ));

            players.add(p);
        }

        return JSONObject.toJSONString(players);
    }

    // 6000 QPS-短  4300--长
    @PostMapping(value = "/one/player")
    public List<Player> getOnePlayer(@RequestBody Player player) {
        List<Player> players=new ArrayList<>();

        for(int i=0;i<1;i++){
            Player p=new Player();
            p.setName("senix.liu["+i+"]");
            p.setAge(23+i);
            p.setAddress("Yangxin Nom"+i);
            p.setGirlFriends(Arrays.asList("dfaa","343434","dafadf","argergre","adfaf","df23ad",
                    "dfaa","343434","dafadf","argergre","adfaf","df23ad"));

            players.add(p);
        }

        return players;
    }

    // 7000 QPS-- 短连接   4500--长连接
    @PostMapping(value = "/one/player/Str")
    public String getOnePlayerStr(@RequestBody Player player) {
        List<Player> players=new ArrayList<>();

        for(int i=0;i<1;i++){
            Player p=new Player();
            p.setName("senix.liu["+i+"]");
            p.setAge(23+i);
            p.setAddress("Yangxin Nom"+i);
            p.setGirlFriends(Arrays.asList("dfaa","343434","dafadf","argergre","adfaf","df23ad",
                    "dfaa","343434","dafadf","argergre","adfaf","df23ad"));

            players.add(p);
        }

        return JSONObject.toJSONString(players);
    }
}
